#include <vector>
#include "helper.h"
#include "model/planet.h"

Planet::Planet(const std::string& texture, float radius) {
    _shader.textureID = loadTexture(texture);//读取纹理
   createIcosphereMesh(_mesh, 3);
   set_radius(radius);
   _mesh.update_buffer();
}

void Planet::set_radius(float radius_new) {
    for (int i = 0; i < this->_mesh.vertices.size(); i++) {
        this->_mesh.vertices[i] *= radius_new / this->radius;
    }
    this->radius = radius_new;
}

float Planet::get_radius() {
    return this ->radius;
}

void Planet::render(glm::mat4 viewMat, glm::mat4 projMat) {
    auto modelMat = getTransMat();
    _shader.render(_mesh, modelMat, viewMat, projMat);
}

Triangle::Triangle(glm::vec3 a, glm::vec3 b, glm::vec3 c) {
    createTriangleMesh(_mesh, a, b, c);
    _mesh.update_buffer();
}

void Triangle::render(glm::mat4 viewMat, glm::mat4 projMat) {
    auto modelMat = getTransMat();
    _shader.render(_mesh, modelMat, viewMat, projMat);
}